package data

import (
	"lnzw/engine/actor"
	"lnzw/server/test/test_fyne/test_3/transport"
	"strconv"
)

var MapMgrCatalog = "mapmgr"

type MapMgr struct {
	actor.DefaultActor
	transport.ProtoDefaultHandler
	maps map[int64]*Map
}

func NewMapMgr() actor.IActor {
	return &MapMgr{maps: make(map[int64]*Map)}
}

func (m *MapMgr) CreateMap(width int, height int) int64 {
	mapId := actor.GenId()
	actorId := strconv.FormatInt(mapId, 10)
	mapactor := actor.StartActor(MapCatalog, actorId).(*Map)
	m.maps[mapId] = mapactor
	mapactor.StartMap(width, height)
	return mapId
}

func (m *MapMgr) GetMapListIds() []int64 {
	mapids := make([]int64, 0, len(m.maps))
	for k, _ := range m.maps {
		mapids = append(mapids, k)
	}
	return mapids
}
